Repository navigation
fix(server): stopping an agent's piped server on macOS names its command - #141
Conversation
macOS `ps -E` shows no environment for its own binaries, such as the `/bin/zsh` an agent CLI runs a command in, and joins argv and environment with spaces. The scanner read argv assignments as environment and read a hidden environment as an empty one, so a command whose shell stays to run a pipeline was never named when its server was stopped, and the agent was woken as if it had finished. Read only what follows argv, treat a hidden environment as unreadable, and take a hidden leader's command name from a process it started in its group. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
ScriptedAlchemy
left a comment
There was a problem hiding this comment.
Second-pass review: I fixed a reproducible argv-prefix collision in dbf1973. With plain ps reporting node server.js and ps -E reporting node server.json COMMAND=c, the parser previously treated the changed command as the same argv and attributed COMMAND=c. The existing parser test now includes that case; it failed before the fix and passes with an exact argv/space boundary.
Validation on the fixed tree: 32 PortScanner tests and 2 AgentContextBudget tests passed, including the real Linux pipeline/group-stop case. Formatting, lint, both Knip passes, GraphQL, and direct server/evals/scripts typechecks passed. The task-runner typecheck wrapper cannot start under this environment's seccomp_unotify restriction; the direct compiler commands completed successfully. The combined tree with #139 merges cleanly and preserves its injected server PID fixtures.
Validation still outstanding: I cannot execute native macOS ps on this Linux host. This pass covers the macOS parser fixtures and real Linux process behavior; it does not independently rerun the native macOS results reported in the PR description. Please retain the native piped-server and hidden-parent checks when verifying on macOS.
The new-head Fork CI run 44016630121 is queued, so I am holding the merge until CI completes successfully.
Problem. On macOS,
PortScanner.test.ts > stops an agent's server…failed onmain, and the product had the same gap. macOSps -Eshows no environment for Apple's own binaries (/bin/zsh,/bin/bash,/bin/sh,/usr/bin/ruby), and it joins argv and environment with spaces. The scanner read argv assignments as environment, and read a hidden environment as an empty one. When Codex runs a command whose shell stays as group leader (npm run dev | tee log,… & wait), stopping its server named no command, so after the turn had settled Codex was woken as if the command had finished. The test failed for a related reason: its stand-in CLI was abash -cwhose argv spelled out the assignment, so the parent looked like it carried the name.Fix. On macOS, the environment is now what
ps -Eprints after the argv that plainpsprints. A hidden environment counts as unreadable, so the existing "an unreadable parent cannot rule out an inherited name" rule now applies on macOS too. A hidden group leader's command name is read from a process it started in its group, which inherited it. The thread-attribution reader uses the same parser, so a spelled-outT3CODE_THREAD_ID=argument no longer attributes a listener. The live test now has the Codex shape: a readable CLI startssh -c 'server | cat'as its own group, with the command named in its environment. It runs on both platforms.Proof (macOS 27.2, Apple silicon).
zsh -lcexecs a single command, so the leader is readable (node, Homebrew/Xcode python). For pipes and& wait, zsh stays as leader andps -Eshows none of its environment.main'sPortScanner.ts: 3 failed, 29 passed. The live test fails atexpect(stops).toEqual([["command-live", true]])with[]. With the fix: 32 passed.vp run check:changed origin/main: all pass./procpaths are unchanged. The leader fallback only applies when the leader's environment is unreadable, which on Linux means another user's process. CI runs the live test on Linux.What remains. A server that is itself an Apple binary (
/usr/bin/ruby -run -e httpd,nc -l) is still not attributed to its thread on macOS, and a fully hidden group still names no command. Closing that needs the command recorded when it starts rather than read back from the process. That's a design choice, not part of this PR.Opus 5.5 via Claude Code in T3 Code.
🤖 Generated with Claude Code